package io.github.jsp.service.impl;

import io.github.jsp.dao.JobRegistryMapper;
import io.github.jsp.model.JobRegistry;
import io.github.jsp.service.JobRegistryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class JobRegistryServiceImpl implements JobRegistryService {
    
    @Autowired
    private JobRegistryMapper jobRegistryMapper;
    
    @Override
    public JobRegistry getById(Integer id) {
        return jobRegistryMapper.selectById(id);
    }
    
    @Override
    public List<JobRegistry> findAll(String registryGroup) {
        return jobRegistryMapper.selectByGroup(registryGroup);
    }
    
    @Override
    public JobRegistry findByKey(String registryGroup, String registryKey) {
        return jobRegistryMapper.selectByGroupAndKey(registryGroup, registryKey);
    }
    
    @Override
    public int registry(JobRegistry jobRegistry) {
        return jobRegistryMapper.insertOrUpdate(jobRegistry);
    }
    
    @Override
    public int removeDead(String registryGroup, String registryKey) {
        return jobRegistryMapper.deleteByGroupAndKey(registryGroup, registryKey);
    }
    
    @Override
    public int removeDeadByTime(long beforeTime) {
        return jobRegistryMapper.deleteBeforeTime(new Timestamp(beforeTime));
    }
}